package com.iqiyi.pps.epg.core.utils.listener;

import com.iqiyi.kiwi.event.annotation.EventListener;
import com.iqiyi.kiwi.message.Message;
import com.iqiyi.kiwi.message.MessageService;
import com.iqiyi.kiwi.message.impl.MessageImpl;
import com.iqiyi.pps.epg.core.utils.ApplicationContextUtil;
import com.iqiyi.pps.epg.core.utils.Constants;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: jason
 * Date: 13-7-2
 * Time: 下午12:25
 * To change this template use File | Settings | File Templates.
 */
@Component
public class MamEventListener {

    private static final Logger logger = LoggerFactory.getLogger(MamEventListener.class);


    @EventListener(value = Constants.EVENT_TYPE_SEND_MESSAGE)
    public void sendMessage(String destination,Long delayTime,Map<String,String> input) {
        logger.info("[module:workflow][action:sendMessage][step:start][event:EVENT_TYPE_SEND_MESSAGE][destination:{}][message:{}]", destination,  JSONObject.fromObject(input).toString());

        MessageService messageService = (MessageService) ApplicationContextUtil.getBean(MessageService.class);
        Message message = new MessageImpl();
        message.setDelay(delayTime);
        message.setDestination(destination);
        //    Map input =  new HashMap<String, String>();
        message.setMap(input);
        messageService.send(message);
        logger.info("[module:workflow][action:sendMessage][step:finish][event:EVENT_TYPE_SEND_MESSAGE][destination:{}][message:{}]", destination,  JSONObject.fromObject(input).toString());

    }

}
